﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace CTOOLS
{
    public partial class FormProgressBar : Form
    {
        private int jsq = 0;
        public int _ipos = 0;
        public string _strT = "";
        private delegate void DelegateFunction(int ipos);
        public FormProgressBar()
        {
            InitializeComponent();
        }

        public FormProgressBar(int _Minimum, int _Maximum)//带参数，表示进度条的范围的最小值和最大值
        {
            InitializeComponent();
            progressBar1.Maximum=_Maximum;//设置范围最大值
            progressBar1.Value = progressBar1.Minimum  = _Minimum;//设置范围最小值
        }
        public void setSent(int value, string strT)//设置进度条当前进度值
        {
            if (value < progressBar1.Maximum)//如果值有效
            {
                progressBar1.Value = value;//设置进度值
                label3.Text = strT;// value.ToString() + "/" + progressBar1.Maximum.ToString();// (value * 100 / progressBar1.Maximum).ToString() + "%";//显示百分比
            }
            Application.DoEvents();//重点，必须加上，否则父子窗体都假死
        }

        //public void setSent(int ipos, string strT)
        //{
        //    _ipos = ipos;
        //    _strT = strT;

        //        button1_Click(null, EventArgs.Empty);

        //}
        //private void SetPos( )
        //{

        //        if (this.progressBar1.InvokeRequired)
        //        {
        //            jsq++;
        //            DelegateFunction df = new DelegateFunction(StartMultiWork);
        //            this.Invoke(df, new object[] { _ipos });

        //    }
        //        else
        //        {
        //            progressBar1.Value = Int32.Parse(_ipos.ToString());
        //            label3.Text = _strT;
        //        }



        //}
        //private void setp()
        //{
        //    SetPos();
        //}
        //private void StartMultiWork( int ipos)
        //{
        //    progressBar1.Value = Int32.Parse(ipos.ToString());
        //    label3.Text = _strT;
        //}

        private void FormProgressBar_Load(object sender, EventArgs e)
        {
            this.Owner.Enabled = false;//设置父窗体不可用
        }

        private void FormProgressBar_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Owner.Enabled = true;//回复父窗体为可用
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Thread multi = new Thread(new ThreadStart(setp));
            //multi.IsBackground = true;
            //multi.Start();
        }
    }
}
